#include "DateTime.h"

namespace nsfq 
{
	CDateTime::CDateTime()
	{
		m_t_time = time(NULL);
		localtime_r( &m_t_time, &m_tm );	
	};

	CDateTime::CDateTime(const time_t time)
	{
		m_t_time = time;
		localtime_r( &m_t_time, &m_tm );	
	}

	string CDateTime::GetDateTime()
	{
		char buf[16] = {0};
		snprintf( buf, sizeof(buf), "%04d%02d%02d%02d%02d%02d", Year(), Month(), Day(), Hour(), Minute(), Second());
		return buf;
	}

	string CDateTime::GetDate()
	{
		char buf[16] = {0};
		snprintf( buf, sizeof(buf), "%04d%02d%02d", Year(), Month(), Day());
		return buf;
	}

	string CDateTime::GetTime()
	{
		char buf[16] = {0};
		snprintf( buf, sizeof(buf), "%02d%02d%02d", Hour(), Minute(), Second());
		return buf;
	}

	string CDateTime::GetFormatDateTime( const char chSep1, const char chSep2 )
	{
		char buf[32] = {0};
		snprintf( buf, sizeof(buf), "%04d%c%02d%c%02d %02d%c%02d%c%02d", Year(), chSep1, Month(), chSep1, Day(), Hour(), chSep2, Minute(), chSep2, Second());
		return buf;
	}

	string CDateTime::ToDay()
	{
		return GetDate();
	}

	string CDateTime::ToHour()
	{
		char buf[16] = {0};
		snprintf( buf, sizeof(buf), "%04d%02d%02d%02d", Year(), Month(), Day(), Hour());
		return buf;
	}

	string CDateTime::ToMinute()
	{
		char buf[16] = {0};
		snprintf( buf, sizeof(buf), "%04d%02d%02d%02d%02d", Year(), Month(), Day(), Hour(), Minute());
		return buf;
	}
};
